package org.xdemo.example.remoteUI.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xdemo.example.remoteUI.entity.tHiDeviceParas;
import org.xdemo.example.remoteUI.entity.tOneDeviceMaker;

import javax.servlet.http.HttpServletRequest;


/**
 * Created by kz on 2017/8/17.
 */

@Controller
@RequestMapping("/remoteUI")
public class remoteUIController {

    @Autowired //自动装载需要的类的实例(目前使用单一实例)
    tOneDeviceMaker thedevide;

    @RequestMapping(value = "testform1")
    public String intoTestform(){
        return "remoteUI/page_HiRUIMain";
//        return "redirect:/login";
    }

    @RequestMapping(value = "test/test1",params = "updata",method = RequestMethod.GET)
    @ResponseBody
    public String function1(){
        System.out.println("this is func1");
        return "TEST1 OK";
    }

    @RequestMapping(value = "test/test1",params = "download",method = RequestMethod.GET)
    @ResponseBody
    public String function2(){
        System.out.println("this is func2");
        return "TEST2 OK";
    }

    @RequestMapping(value = "test/test1",params = "download",method = RequestMethod.POST)
    @ResponseBody
    public String function3(){
        System.out.println("this is func3");
        return "TEST3 OK";
    }

//对每一个session产生一个device
    @RequestMapping(value="getgroupone", method = RequestMethod.GET)
    public @ResponseBody tHiDeviceParas getGroupOne(HttpServletRequest request){

        if( request.getSession().getAttribute("thedevice") == null){
            request.getSession().setAttribute("thedevice",thedevide.makeOneDevcie());

        }
     return (tHiDeviceParas)request.getSession().getAttribute("thedevice");
    }



}
